package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.ITMSWebService;

import java.util.HashMap;
import java.util.Map;

/**
 * ITMS_WebService_Imp_factoryReset
 * ITMS-业务重发
 * @author xuzhi
 *
 */
public class ITMS_WebService_Imp_factoryReset implements WorkInterFace {

	@Override
	public String getName() {
		return "ITMS-业务重发";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in=new Attr[2];
		in[0]=new Attr("pppoe","用户宽带账号(两个参数选填一个)", AttrType.TYPE_String,true);
		in[1]=new Attr("loid","终端SN号(两个参数选填一个)",AttrType.TYPE_String,true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[9];
		out[0]=new Attr("ReturnCode", "0：成功；其它：失败", AttrType.TYPE_Int, true);
		out[1]=new Attr("return", "返回return", AttrType.TYPE_String, true);
		out[2]=new Attr("workId", "操作流水号,对应移动运维的工单流水号", AttrType.TYPE_String, true);
		out[3]=new Attr("pppoe", "宽带帐号", AttrType.TYPE_String, true);
		out[4]=new Attr("loId", "逻辑ID", AttrType.TYPE_String, true);
		out[5]=new Attr("status", "下发状态；表示业务重发业务的状态:01: 成功；02: 失败；", AttrType.TYPE_String, true);
		out[6]=new Attr("failed_reason", "重发失败原因", AttrType.TYPE_String, true);
		out[7]=new Attr("log", "服务器返回的soapxml", AttrType.TYPE_String, true);
		out[8]=new Attr("Errormsg", "服务器返回的错误信息,当ReturnCode为0的时候就不必去读取", AttrType.TYPE_String, false);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn=new AttrsIn();
		ITMSWebService webService=new ITMSWebService();
		Map<String,Object> map=new HashMap<String, Object>();
		//Get into arguments
		attrsIn.setFunctionName("factoryReset");
		attrsIn.setRequestMessage("<loId>"+webService.dealString((String) data.get("loId"))+"</loId>" +
	            "<pppoe>"+webService.dealString((String) data.get("pppoe"))+"</pppoe>" +
	            "<workId></workId>");
		//Get soapxml
		String returnXml=webService.WebServiceInit(attrsIn,1);
		String flag=webService.getPattern("return", returnXml);
		
		if(flag.length()>0){
			map.put("ReturnCode", 0);
			map.put("return", webService.getPattern("return", returnXml));
			map.put("workId", webService.getPattern("workId", returnXml));
			map.put("pppoe", webService.getPattern("pppoe", returnXml));
			map.put("loId", webService.getPattern("loId", returnXml));
			map.put("status", webService.getPattern("status", returnXml));
			map.put("failed_reason", webService.getPattern("failed_reason", returnXml));
			map.put("log", returnXml);
			map.put("Errormsg", "");
		}else{
			map.put("ReturnCode", 1);
			map.put("return", "");
			map.put("workId", "");
			map.put("pppoe", "");
			map.put("loId", "");
			map.put("status", "");
			map.put("failed_reason", "");
			map.put("log", returnXml);
			map.put("Errormsg", "网元侧执行出错，处理请求失败");
		}
		
		return map;
	}

}
